package com.nineclock.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nineclock.system.pojo.SysCompany;
import com.nineclock.system.pojo.SysCompanyUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 淮晓欢
 * @Company http://www.huaixiaohuan.com
 * @Version 1.0
 */
@Mapper
public interface SysCompanyUserMapper extends BaseMapper<SysCompanyUser> {

    @Select("SELECT scu.* FROM sys_role sr,sys_company_user scu,sys_company_user_role scur where scu.company_id= #{companyId} and sr.role_name=\"ROLE_ADMIN_SYS\" AND sr.id=scur.role_id AND scu.id=scur.company_id")
    SysCompanyUser selectCurrentAdmin(@Param("companyId") Long companyId);

    @Select("select count(0) from sys_company_user where work_number = #{workNumber}")
    int checkWorknumberCount(String workNumber);

    @Select("select * from sys_company where id in (select company_id from sys_company_user where user_id = #{userId})")
    List<SysCompany> queryCompanyListByUserId(Long userId);
}
